<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function fn(type, url) {
            return new Promise((res, rej) => {
                var xhr = new XMLHttpRequest()
                xhr.open(type, url)
                xhr.send()
                xhr.responseType = 'json'
                xhr.onload = () => {
                    res(xhr.response)
                }
                xhr.onerror = (e) => {
                    rej(e)
                }
            })
        }
        fn('get', 'https://liu.zzgoodqc.cn./teas').then(val => {
            console.log(val);
        })
            .catch(e => {
                console.log(e);

            })



        function fn(type, url, data) {
            return new Promise((res, rej) => {
                var xhr = new XMLHttpRequest();
                xhr.open(type, url);
                xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
                xhr.responseType = 'json';
                xhr.onload = () => {
                    res(xhr.response);
                };
                xhr.onerror = (e) => {
                    rej(e);
                };
                xhr.send(JSON.stringify(data));
            });
        }
        fn('post', 'https://liu.zzgoodqc.cn/teas', {
            name: '龙井',
            type: '井',
            price: 10
        }).then(val => {
            console.log(val);
        }).catch(e => {
            console.log(e);
        });




   
        function fn(type, url) {
            return new Promise((res, rej) => {
                var xhr = new XMLHttpRequest();
                xhr.open(type, url);
                  xhr.send();
                xhr.responseType = 'json';
                xhr.onload = () => {
                    res(xhr.response);
                };
                xhr.onerror = (e) => {
                    rej(e);
                };
              
            });
        }

        fn('get', 'https://liu.zzgoodqc.cn/teas/11933')
            .then(val => {
                console.log(val);
            })
            .catch(e => {
                console.log(e);
            });


    </script>
</body>

</html>